package com.cpj.bsyyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cpj.bsyyzx.entity.BedRecord;
import com.cpj.bsyyzx.entity.BedUser;
import com.cpj.bsyyzx.service.IBedRecordService;
import com.cpj.bsyyzx.service.IBedUserService;
import com.cpj.bsyyzx.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-05-14
 */
@RestController
@RequestMapping("/bedUser")
public class BedUserController {
    @Autowired
    IBedRecordService bedRecordService;
    @Autowired
    IBedUserService bedUserService;
@RequestMapping("getOneByBedNum")
    CommonResult getOneByBedNum(String bedNum){
    QueryWrapper wrapper=new QueryWrapper();
    wrapper.eq("bed_information",bedNum);
    BedRecord bedRecord= bedRecordService.getOne(wrapper);
    QueryWrapper wrapper1=new QueryWrapper();
    wrapper1.eq("record_num",bedRecord.getRecordNum());
    return CommonResult.success(bedUserService.getOne(wrapper1));
}

    boolean saveOrUpdate(BedUser beduser){
        return bedUserService.saveOrUpdate(beduser);
    }
    boolean delete(String fileNum){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("record_num",fileNum);
        BedUser bedUser=bedUserService.getOne(wrapper);
        return bedUserService.removeById(bedUser.getId());
    }


}
